<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Mail;
use DB;
class MailController extends Controller
{
    //邮件
    public function send()
    {
        
        // echo $mail;die;
        // $mail = DB::talbe('users')->select('email')->where('id',31)->get();
        $number = rand(1000,9999);
        session()->put('mailCode',$number);
        $flag = Mail::send('home.mail',['name'=>$number],function($message){ 
            // $to = '1529870439@qq.com';
            $mail = $_GET['mail'];

            $message ->to($mail)->subject('邮箱验证'); 
        }); 

        if($flag){
            echo '发送成功';
        }else{
            echo '发送失败';
        }
    }

    public function getCode()
    {
        if($_GET['code']==session()->get('mailCode')){
            echo 1;
        }else{
            echo 0;
        }
    }

}
